package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.AccessBean;
import com.lc.pianostudent.bean.ShopBean;
import com.lc.pianostudent.bean.ShopIndexBean;
import com.lc.pianostudent.bean.ShophomeBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.HOME_INDEX)
public class PostHomeIndex extends BaseAsyPost {

    public String user_id;
    public PostHomeIndex(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostHomeIndexInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostHomeIndexInfo info = new PostHomeIndexInfo();

            JSONArray array = object.optJSONArray("type");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);
                    ShopIndexBean shopIndexBean = new ShopIndexBean();
                    shopIndexBean.setId(o.optString("id"));
                    shopIndexBean.setTitle(o.optString("title"));
                    info.shopIndexList.add(shopIndexBean);

                }
            }
            info.sex = object.optString("sex");
            info.mote = object.optString("mote");
            array = object.optJSONArray("goods");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject jo = array.optJSONObject(i);
                    ShophomeBean shophomeBean = new ShophomeBean();
                    shophomeBean.setId(jo.optString("id"));
                    shophomeBean.setTitle(jo.optString("title"));
                    shophomeBean.setExpiretime(jo.optString("expiretime"));
                    shophomeBean.setShopid(jo.optString("shopid"));
                    shophomeBean.setTypeid(jo.optString("typeid"));
                    shophomeBean.setPicshow(jo.optString("picshow"));

                    info.homeList.add(shophomeBean);

                }
            }

            JSONArray accseetype = object.optJSONArray("accseetype");
            if(accseetype != null || accseetype.length() != 0){
                for(int i = 0;i<accseetype.length();i++){
                    JSONObject o = accseetype.optJSONObject(i);
                    ShopIndexBean shopIndexBean = new ShopIndexBean();
                    shopIndexBean.setId(o.optString("id"));
                    shopIndexBean.setTitle(o.optString("title"));
                    info.accseetypeIndexList.add(shopIndexBean);

                }
            }
            JSONObject hair = object.optJSONObject("hair");
            info.hair_id = hair.optString("id");
            info.hair_type = hair.optString("type");
            info.hair_picurl = hair.optString("picurl");

            JSONObject jack = object.optJSONObject("jack");
            info.jack_id = jack.optString("id");
            info.jack_type = jack.optString("type");
            info.jack_picurl = jack.optString("picurl");

            JSONObject download = object.optJSONObject("download");
            info.download_id = download.optString("id");
            info.download_type = download.optString("type");
            info.download_picurl = download.optString("picurl");

            JSONObject shose = object.optJSONObject("shose");
            info.shose_id = shose.optString("id");
            info.shose_type = shose.optString("type");
            info.shose_picurl = shose.optString("picurl");

            JSONObject suit = object.optJSONObject("suit");
            info.suit_id = suit.optString("id");
            info.suit_type = suit.optString("type");
            info.suit_picurl = suit.optString("picurl");

            JSONObject expression = object.optJSONObject("expression");
            info.expression_id = expression.optString("id");
            info.expression_type = expression.optString("type");
            info.expression_picurl = expression.optString("picurl");

            JSONArray access = object.optJSONArray("access");
            if(access != null || access.length() != 0){
                for(int i = 0;i<access.length();i++){
                    JSONObject o = access.optJSONObject(i);
                    AccessBean accessBean = new AccessBean();
                    accessBean.setId(o.optString("id"));
                    accessBean.setPicurl(o.optString("picurl"));
                    accessBean.setType(o.optString("type"));
                    info.accessShowList.add(accessBean);

                }
            }

            JSONObject user = object.optJSONObject("user");
            info.huangguan = user.optString("huangguan");
            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostHomeIndexInfo {

        public String code, message,hair_id,hair_type,hair_picurl,jack_id,jack_type,jack_picurl,
                download_id,download_type,download_picurl,shose_id,shose_type,shose_picurl
                ,suit_id,suit_type,suit_picurl,expression_id,expression_type,expression_picurl,sex,huangguan,mote;


        public List<ShopIndexBean> shopIndexList = new ArrayList<>();
        public List<ShopIndexBean> accseetypeIndexList = new ArrayList<>();
        public List<ShophomeBean> homeList = new ArrayList<>();
        public List<AccessBean> accessShowList = new ArrayList<>();
    }

}
